<template>
  <div class="all-job-resume">
    <div class="all-job-resume-head">
      <el-col :span="23">
        <span class="all-job-resume-line"></span>
        期望职位
        <span class="all-job-resume-sub-text">必填</span>
      </el-col>
      <el-col :span="1" v-if="data.length < 3">
        <i class="el-icon-circle-plus plus-add" @click="addContent"></i>
      </el-col>
    </div>

    <expectation-job-list
      v-for="(item,index) in data"
      :key="index"
      :data="item"
      :form="form"
      :enterpriseType="enterpriseType"
      :practiceType="practiceType"
      @on-pitch="cancel"
    ></expectation-job-list>

    <div class="edit-content" v-if="form.sta == 1 && form.editSta == -1">
      <div class="all-job-resume" style="padding:24px 0 0 0; background:#f7fdff;">
        <el-form label-width="100px" label-position="right">
          <el-row>
            <el-col :span="12">
              <el-form-item label="期望城市">
                <el-cascader
                  :options="city"
                  @change="getData"
                  placeholder="所在城市"
                  v-model="workCity"
                ></el-cascader>
              </el-form-item>
              <el-form-item label="期望企业类型">
                <el-select class="all-input" v-model="params.hopeCompanyType">
                  <el-option
                    v-for="(item,index) in enterpriseType"
                    :key="index"
                    :label="item.content"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="11" :offset="1">
              <el-form-item label="期望执业类型">
                <!-- <el-select class="all-input" v-model="params.hopeLicence">
                  <el-option
                    v-for="(item,index) in practiceType"
                    :key="index"
                    :label="item.content"
                    :value="item.id"
                  ></el-option>
                </el-select>-->
                <el-cascader :options="practiceType||[]" :props="props" v-model="hopeLicence"></el-cascader>
              </el-form-item>
              <el-form-item label="期望年薪">
                <el-col :span="16">
                  <el-input v-model="params.salaryPerMonthLow" class="theme-input money-input"></el-input>&nbsp;-&nbsp;
                  <el-input v-model="params.salaryPerMonthHigh" class="theme-input money-input"></el-input>W/&nbsp;
                  <el-input v-model="params.yearNum" class="theme-input money-input"></el-input>&nbsp;年
                </el-col>
                <el-col :span="8">
                  <el-radio-group v-model="params.taxType">
                    <el-radio :label="0">税前</el-radio>
                    <el-radio :label="1">税后</el-radio>
                  </el-radio-group>
                </el-col>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item class="form-button-right">
            <el-button class="ghost-button" @click="cancel">取消</el-button>
            <el-button class="submit-button" @click="onSubmit">确认</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import expectationJobList from './list/expectation-job-list'
import { chinaOptions, CodeToText, TextToCode } from '@/assets/utils/china.js'
export default {
  props: ['form', 'enterpriseType', 'practiceType', 'data'],
  data() {
    return {
      city: chinaOptions,
      workCity: [],
      hopeLicence: [],
      params: {
        id: '',
        hopeCity: '',
        hopeCompanyType: '',
        hopeLicence: '',
        salaryPerMonthHigh: '',
        salaryPerMonthLow: '',
        yearNum: '',
        taxType: ''
      },
      props: {
        value: 'licenseTypeId',
        children: 'licenseSonList',
        label: 'licenseType'
      }
    }
  },
  methods: {
    check() {
      if (
        this.params.hopeCity == '' ||
        this.params.hopeCompanyType == '' ||
        this.hopeLicence == [] ||
        this.params.salaryPerMonthLow == '' ||
        this.params.salaryPerMonthHigh == '' ||
        this.params.yearNum == '' ||
        this.params.taxType === ''
      ) {
        //console.log(this.params.taxType == '')
        _g.message('数据不能为空', 'warning')
        return false
      }
      if (this.params.salaryPerMonthHigh - this.params.salaryPerMonthLow > 5) {
        _g.message('期望年薪最大值与最小值不能超过5W', 'warning')
        return false
      }
      return true
    },
    addContent() {
      //点击添加按钮
      this.form.sta = 1
      this.form.editSta = -1
    },
    cancel() {
      this.$emit('on-pitch', true)
      this.form.sta = -1
      this.form.editSta = -1
    },
    onSubmit() {
      if (!this.check()) return false
      this.params.hopeLicence = this.hopeLicence[1]
      _g.apiPost('/talent/updateJobIntention.do', this.params).then(res => {
        _g.toMessage(res)
        this.cancel()
        this.emptyData()
      })
    },
    getData(val) {
      // let l = []
      // for (let i in val) {
      //   l.push(CodeToText[val[i]])
      // }
      this.params.hopeCity = val.join('-')
    },
    emptyData() {
      this.params.id = ''
      this.workCity = []
      this.params.hopeCompanyType = ''
      this.hopeLicence = []
      this.params.salaryPerMonthHigh = ''
      this.params.salaryPerMonthLow = ''
      this.params.yearNum = ''
      this.params.taxType = ''
    }
  },
  components: {
    expectationJobList
  }
}
</script>

<style lang="scss" scoped>
</style>
